package com.lee.sender;


import nl.justobjects.pushlet.core.Dispatcher;
import nl.justobjects.pushlet.core.Event;

import com.lee.model.Msg;
import com.lee.model.TextMsg;

public class PageSender
{
	public static final String eventID = "/lee/ww";
	
	//public static final String keyFromUser = "fromUser";
	
	public static void sendMsgToPage(Msg msg)
	{
		Event event = Event.createDataEvent(eventID);
		
		if(msg.getType().equalsIgnoreCase("text"))
		{
			TextMsg tm =  (TextMsg)msg;
			String fromUser = tm.getFromUserName();
			String toUser = tm.getToUserName();
			String content = tm.getContent();
			String time = tm.getCreateTime();
			
			event.setField("fromUser", fromUser);
			event.setField("toUser", toUser);
			event.setField("content", content);
			event.setField("time", time);
		}
		event.setField("msg", "test...");
		
		Dispatcher.getInstance().multicast(event);
		
		System.out.println("[PageSender] send msg, msg id: " + msg.getMsgId());
	}
}
